from pathlib import Path
import csv
from datetime import datetime
import matplotlib.pyplot as plt
from settings import rc_params_toChinese, set_temperatureAndRain_ax

path = Path('weather_data/sitka_weather_2021_simple.csv')
lines = path.read_text().splitlines()

reader = csv.reader(lines)
header_row = next(reader)

# 提取日期、最高温度和最低温度
dates, highs, lows = [], [], []
for row in reader:
    current_date = datetime.strptime(row[2], '%Y-%m-%d')
    high = int(row[4])
    low = int(row[5])
    dates.append(current_date)
    highs.append(high)
    lows.append(low)

# 根据日期、最高温度和最低温度绘图
plt.style.use('seaborn-v0_8')
plt.rcParams.update(rc_params_toChinese)
fig, ax = plt.subplots()
ax.plot(dates, highs, color='red', alpha=0.5)
ax.plot(dates, lows, color='blue', alpha=0.5)
# 给图中区域着色
ax.fill_between(dates, highs, lows, facecolor='blue', alpha=0.1)

# 设置绘图的格式
title = "2021年最高温度和最低温度"
ylabel = "温度(F)"
ax = set_temperatureAndRain_ax(ax, title, ylabel)
fig.autofmt_xdate()

plt.show()